@tool
class_name FloatingTexture
extends Control

@export var texture: Texture2D
@export_range(0, 1) var offset: float:
	get:
		return offset
	set(val):
		offset = val
		_aspect_offset = minf(get_rect().size.x, get_rect().size.y) * offset
		queue_redraw()

var _aspect_offset: float = 0

func _notification(what: int) -> void:
	if what == NOTIFICATION_RESIZED:
		_aspect_offset = minf(get_rect().size.x, get_rect().size.y) * offset
		queue_redraw()

func _draw() -> void:
	if !texture:
		return
	
	var rect = get_rect()
	if !is_zero_approx(offset):
		rect.position = Vector2.ZERO
		draw_texture_rect(texture, rect, false, Color(0x00000080))

	rect.position = _aspect_offset * Vector2.UP
	draw_texture_rect(texture, rect, false)
